/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * gameMain.java
 *
 * Created on Aug 28, 2011, 5:30:19 PM
 */
package crosswordsgame;

import com.jtattoo.plaf.aero.AeroLookAndFeel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 *
 * @author BAOBAO
 */
public class gameMain extends javax.swing.JFrame {

    Thread timer;
    int _time;

    /** Creates new form gameMain */
    public gameMain() {

        initComponents();
        set_time();// call timer and display
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnNewGame = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnHightScores = new javax.swing.JButton();
        btnHistory = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();
        btnHelp = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        lblHint = new javax.swing.JLabel();
        txtHint = new javax.swing.JTextField();
        lblUser = new javax.swing.JLabel();
        lblTimer = new javax.swing.JLabel();
        lblBackground = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(850, 704));
        setResizable(false);

        jPanel1.setLayout(null);

        btnNewGame.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        btnNewGame.setForeground(new java.awt.Color(255, 255, 255));
        btnNewGame.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/play.png"))); // NOI18N
        btnNewGame.setText(" New Game");
        btnNewGame.setBorder(null);
        btnNewGame.setBorderPainted(false);
        btnNewGame.setContentAreaFilled(false);
        jPanel1.add(btnNewGame);
        btnNewGame.setBounds(251, 23, 100, 50);

        btnSave.setFont(new java.awt.Font("Arial", 1, 11));
        btnSave.setForeground(new java.awt.Color(255, 255, 255));
        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.png"))); // NOI18N
        btnSave.setText("Save ");
        btnSave.setBorder(null);
        btnSave.setBorderPainted(false);
        btnSave.setContentAreaFilled(false);
        jPanel1.add(btnSave);
        btnSave.setBounds(363, 23, 80, 50);

        btnHightScores.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        btnHightScores.setForeground(new java.awt.Color(255, 255, 255));
        btnHightScores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/hightscore.png"))); // NOI18N
        btnHightScores.setText("Hight Scores");
        btnHightScores.setBorder(null);
        btnHightScores.setBorderPainted(false);
        btnHightScores.setContentAreaFilled(false);
        jPanel1.add(btnHightScores);
        btnHightScores.setBounds(460, 23, 110, 50);

        btnHistory.setFont(new java.awt.Font("Arial", 1, 11));
        btnHistory.setForeground(new java.awt.Color(255, 255, 255));
        btnHistory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/history.png"))); // NOI18N
        btnHistory.setText("  History");
        btnHistory.setBorder(null);
        btnHistory.setBorderPainted(false);
        btnHistory.setContentAreaFilled(false);
        jPanel1.add(btnHistory);
        btnHistory.setBounds(580, 23, 91, 50);

        btnExit.setFont(new java.awt.Font("Arial", 1, 11));
        btnExit.setForeground(new java.awt.Color(255, 255, 255));
        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.png"))); // NOI18N
        btnExit.setText("Exit");
        btnExit.setBorder(null);
        btnExit.setBorderPainted(false);
        btnExit.setContentAreaFilled(false);
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });
        jPanel1.add(btnExit);
        btnExit.setBounds(760, 23, 70, 50);

        btnHelp.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        btnHelp.setForeground(new java.awt.Color(255, 255, 255));
        btnHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help.png"))); // NOI18N
        btnHelp.setText(" Help");
        btnHelp.setBorder(null);
        btnHelp.setBorderPainted(false);
        btnHelp.setContentAreaFilled(false);
        btnHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHelpActionPerformed(evt);
            }
        });
        jPanel1.add(btnHelp);
        btnHelp.setBounds(670, 23, 80, 50);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pause.png"))); // NOI18N
        jPanel1.add(jButton1);
        jButton1.setBounds(70, 520, 50, 30);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/continue.png"))); // NOI18N
        jButton2.setBorder(null);
        jPanel1.add(jButton2);
        jButton2.setBounds(260, 520, 60, 30);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/finishe.png"))); // NOI18N
        jButton3.setText(" Finish Game");
        jPanel1.add(jButton3);
        jButton3.setBounds(340, 520, 130, 30);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/hint.png"))); // NOI18N
        jButton4.setText("Hint");
        jPanel1.add(jButton4);
        jButton4.setBounds(153, 520, 90, 30);

        lblHint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/hint.png"))); // NOI18N
        lblHint.setText("Hint:");
        jPanel1.add(lblHint);
        lblHint.setBounds(50, 120, 70, 30);

        txtHint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHintActionPerformed(evt);
            }
        });
        jPanel1.add(txtHint);
        txtHint.setBounds(50, 150, 420, 20);

        lblUser.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        lblUser.setForeground(new java.awt.Color(255, 255, 255));
        lblUser.setText("Hello :David");
        jPanel1.add(lblUser);
        lblUser.setBounds(650, 120, 90, 20);

        lblTimer.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblTimer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/timer.png"))); // NOI18N
        lblTimer.setText(" 05:00");
        jPanel1.add(lblTimer);
        lblTimer.setBounds(210, 460, 120, 30);

        lblBackground.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/userMain.png"))); // NOI18N
        jPanel1.add(lblBackground);
        lblBackground.setBounds(0, 0, 850, 704);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 850, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-866)/2, (screenSize.height-742)/2, 866, 742);
    }// </editor-fold>//GEN-END:initComponents

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnExitActionPerformed

    private void btnHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHelpActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnHelpActionPerformed

    private void txtHintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHintActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHintActionPerformed

    public void set_time() {

        timer = new Thread(new Runnable() {

            public void run() {
                int p = 100;

                int m = p / 60;
                int s = p - 60 * m;
                int kk = 0;
                for (int i = p; i >= 0; i--) {
                    _time = i;
                    kk++;
                    final int ii = kk;
                    final int mm = m;
                    final int ss = s;
                    try {
                        SwingUtilities.invokeLater(new Runnable() {

                            public void run() {

                                if (mm < 10) {
                                    if (ss < 10) {
                                        update_timer("0" + mm + " : " + "0" + ss);

                                    } else {
                                        update_timer("0" + mm + " : " + ss);
                                    }
                                } else {
                                    if (ss < 10) {
                                        update_timer(mm + " : " + "0" + ss);
                                    } else {
                                        update_timer(mm + " : " + ss);
                                    }
                                }


                            }
                        });
                        java.lang.Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        ;
                    }
                    if (m == 0 && s == 0) {
                        JOptionPane.showMessageDialog(null, "Time out");
                        // solve();
                    }
                    if (s == 0) {
                        m--;
                        s = 60;
                    }
                    s--;

                }
            }
        });
        timer.start();

    }

    public void update_timer(String text) {
        lblTimer.setText(text);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                try {
//                    UIManager.setLookAndFeel(new McWinLookAndFeel());
//                    UIManager.setLookAndFeel(new LunaLookAndFeel());
//                    UIManager.setLookAndFeel(new AcrylLookAndFeel());
//                    UIManager.setLookAndFeel(new AluminiumLookAndFeel());
                    UIManager.setLookAndFeel(new AeroLookAndFeel());
                    new gameMain().setVisible(true);

                } catch (Exception e) {
                    e.printStackTrace();
                }


            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnHelp;
    private javax.swing.JButton btnHightScores;
    private javax.swing.JButton btnHistory;
    private javax.swing.JButton btnNewGame;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblBackground;
    private javax.swing.JLabel lblHint;
    private javax.swing.JLabel lblTimer;
    private javax.swing.JLabel lblUser;
    private javax.swing.JTextField txtHint;
    // End of variables declaration//GEN-END:variables
}
